package com.forum.controller.admin;

import com.forum.constant.MessageConstant;
import com.forum.entity.Categories;
import com.forum.result.Result;
import com.forum.service.CategoriesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags ="分类接口")
@RestController
@RequestMapping("/admin/categories")
public class CategoriesController {

    @Autowired
    private CategoriesService categoriesService;

    @ApiOperation("查询分类")
    @PostMapping("/query")
    public Result<List<Categories>> queryCategories(){
        List<Categories> categories = categoriesService.queryCategories();
        return Result.success(categories);
    }
    @ApiOperation("添加分类")
    @PostMapping("/save")
    public Result InertCategories(@RequestBody Categories category){
        categoriesService.insert(category);
        return Result.success(MessageConstant.INSERT_SUCCESS);
    }

    @ApiOperation("修改分类")
    @PutMapping("/update")
    public Result updateCategories(@RequestBody Categories category){
        categoriesService.update(category);
        return Result.success(MessageConstant.UPDATE_SUCCESS);
    }

    @ApiOperation("删除分类")
    @DeleteMapping("/{id}")
    public Result DeleteById(@PathVariable("id") Long id){
        categoriesService.delete(id);
        return Result.success(MessageConstant.DELETE_SUCCESS);
    }

}
